---
title: "README: Latta et al 2017 PeerJ"
author: "brouwern@gmail.com"
date: "May 3, 2017"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


# Contents

1. Coding of species traits
2. Details on custom functions used for data processing




# Coding of species traits

Original covariates coded by S Latta.
Some codings changed for final MS; some factor levels to combined rarer levels of factors


## Status: 

* PR = permanent resident (includes alt. mig)
* M = seasonal resident

## Types of migrants: 

* L = latitudinal migrant; 
* E = known to be nomadic or elevational migrant (Blake and Loiselle 1991, 2000, 2001; Reid et al. 2012; Stiles and Skutch 1989)

## Primary habitat: 

* F = primary forest; 
* S = secondary forest scrub or edge; 
* O = other non forest (Stotz et al. 1996)

## Habitat breadth: 

Number of habitats occupied (1-7) as recorded by Stotz et al. (1996)

## Sensitivity to disturbance: 

* H = high
* M = medium
* L = low

##Conservation priority: 

* 1 = urgent; 
* 2 = high; 
* 3 = medium; 
* 4 = low

## Foraging guild: 

(Boyle and Sigel 2015a,b; Stiles and Skutch 1989)

* C = carnivore, 
* I = insectivore, 
* F = frugivore/granivore, 
* N = nectarivore, 
* O = omnivore 

levels of this factor were combined into I, O, and F/N

## Foraging strata: 

From Stotz et al. 1996' These are not mutualy exclusive categories

* T = terrestrial, 
* U = understory, 
* M = mid-story, 
* C = canopy 
 

# Custom functions used for data processing


## FX_run_multi_level_model

Runs a series of nested GLMMs with temporal trends (year), traits, month,  year*trait interactions, etc. The general form of the model is represented below by the "null" model:

glmer(N ~   1 +      #spp-level intercept
                     (1|name) +    
                     
                     #slopes for each spp w/in each moth
                     (year.cent|name:month) + 
                     
                     #intercept for each year
                     (1|year) +    
                     
                     #intercept for each year nested w/in month
                     (1|year:month) +  
                     
                     #ind level raned for pois-norm to reduce overdisp
                     (1|i),                   
                   family = poisson,
                   data = df)

## FX_run_multi_level_model_NO_MONTH_EFFECT

Runs multilevel model for latitudinal migrants, which only occur in January and so the models contain no month effect.


## FX_anova_extract

Extract information from anova() function called on nested models.

## FX_multlevel_model_helper_functions

Series of functions to carry out the tasks of processing fitted models contained in a list produced by my function run.multlev.model()

anova.from.list()
make.anova.list()
make.anova.table()
label.anova.table()
compile.everything()



## FX_multlevel_model_wrapper_for_helper_functions

Runs the helper functions found in the script FX_multlevel_model_helper_functions.R and puts it into a list

## FX_round_df_columns

Round off data values in a dataframe w/o re-setting global settings for diplaying data.